package com.litong.rms.dao.impl;
import java.util.List;

import com.litong.rms.bean.Role;
import com.litong.rms.dao.RoleDao;

public class RoleDaoImpl extends BaseDaoImpl implements RoleDao{

	/**
	 * 
	 */
	private static final long serialVersionUID = 7564271522411303921L;

	public void addRole(Role role) {
		save(role);
	}

	public void deleteRole(Role role) {
		//role = findRole(role);
		delete(role);
	}

	public Role findRole(Role role) {
		String roleName = role.getRoleName().trim();
		String queryString = "from Role where roleName = ?";
		Object[] values = new String[1];
		values[0] = roleName;
		List<Role> roleList = this.find(queryString, values);
		
		if(roleList!=null&&!roleList.isEmpty()){
			Role Role = roleList.get(0);
			return Role;
		}else{
			return null;
		}	
	}

	public void updateRole(Role role) {
		saveOrUpdate(role);
		
	}

	@SuppressWarnings("unchecked")
	public List<Role> getRoleList() {
		String queryString = "from Role";
		List<Role> roleList = getEntityList(queryString);
		if(roleList!=null&&!roleList.isEmpty()){
			return roleList;
		}
		return null;
	}

	public Role findById(int id) {
		int value = id;
		String queryString = "from Role where roleId = ?";
		List<Role> roleList = this.find(queryString, value);	
		if(roleList!=null&&!roleList.isEmpty()){
			Role Role = roleList.get(0);
			return Role;
		}else{
			return null;
		}	
	}
	
	
}
